#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
@Time        : 2021/11/4 14:59
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : fingerprint_morphology.py
@Version     : Version 1.0.0
@Description : TODO
@Created By  : PyCharm
"""
from skimage.io import imread
from DIP_experiment_5.util import contrast_show
from skimage.morphology import square, binary_closing, binary_opening

FONT_PATH = "C:/Windows/Fonts/simhei.ttf"
IM_PATH = "../experiment_fig/fingerprint.png"  # RGBA
im = imread(IM_PATH, as_gray=True)  # 读入为greyscale image
square_elem = square(width=3)  # 生成3*3的正方型结构元素
closing_im = binary_closing(im, square_elem)  # 进行闭操作
opening_im = binary_opening(im, square_elem)  # 进行开操作
opening_closing_im = binary_closing(opening_im, square_elem)  # 先进行开操作再进行闭操作
im_dict = {"原始图像": im, "闭操作图像": closing_im,
           "开操作图像": opening_im, "先开后闭图像": opening_closing_im}
contrast_show(im_dict, (2, 2),hspace=0.3, font=FONT_PATH)
